<template>
	<view class="pages">
		<view class="topssechar">
			<view class="searchs">
				<image src="/static/coment/icon-search@2x.svg" mode="aspectFill" class="search_icon"></image>
				<input type="text" v-model="paramsData.searchValue" confirm-type="search" @confirm="searchConfirm"
					placeholder="搜索我的订单" class="full_flex" />
			</view>

		</view>
		<view class="tabBar">
			<view :class="['itemsTOp',data.indexOfId == item.id?'selectClass':'']" v-for="(item,index) in data.tableList"
				:key="index" @click="handleTab(item.id)">
				{{item.text}}
				<view class="lins" v-if="item.id == data.indexOfId"></view>
			</view>
		</view>
		<view style="width: 100%;height: 16rpx;"></view>
		<block v-for="(item,index) in orderList " :key="index">
			<allVue :itemObj="item" @reloadPage='reloadPage'></allVue>
		</block>
		<block v-if="orderList.length == 0">
			<view class="konList">
				<image src="https://hosue-omo.oss-cn-shenzhen.aliyuncs.com/assets/noData.png" mode="aspectFit"
					class="kongs"></image>
				<view class="titils">
					～没有数据～
				</view>
			</view>
		</block>
	</view>
</template>

<script setup>
	import allVue from './components/all.vue';
	import {
		orderPage
	} from './js/api.js'
	import {
		ref,
		reactive,
		onMounted
	} from 'vue';
	import {
		onReachBottom,
		onLoad,
		onShow
	} from '@dcloudio/uni-app'
	// 状态:0-待支付，1-支付中，2-已取消，3-已完成，4-支付失败
	const data = reactive({
		tableList: [{
			id:-1,
				text: '全部'
			},
			{
				id:0,
				text: '待支付'
			},
			{
				id:3,
				text: '已完成'
			},
		],
		indexOfId: -1,
	})
	const paramsData = reactive({
		pageNum: 1,
		pageSize: 10,
		searchValue: '',
		status: '',
	})
	const orderList = ref([])
	const getOrderList = async () => {
		let res = await orderPage(paramsData)
		console.log(res)
		
		
		let list = res.data.data.list
		if (paramsData.pageNum == 1) {
			orderList.value = list
		} else {
			orderList.value = orderList.value.concat(list)
		}
		if (list.length < 10) isReach.value = false
	}
	const handleTab =(id)=>{
		data.indexOfId = id
		paramsData.pageNum = 1
		paramsData.status = id
		if(id == -1)paramsData.status = ''
		getOrderList()
	}
	const searchConfirm = ()=>{
		paramsData.pageNum = 1
		getOrderList()
	}
	onMounted(() => {
		
	})
	const reloadPage = ()=>{
		paramsData.pageNum = 1
		getOrderList()
	}
	const isReach = ref(true)
	onReachBottom(()=>{
		if (!isReach.value) return
		paramsData.pageNum++
		getOrderList()
	})
	onLoad((options)=>{
		if(options.source == 'unpaid'){
			paramsData.status = 0
			data.indexOfId = 0
		}
		if(options.source == 'complete'){
			paramsData.status = 3
			data.indexOfId = 3
		}
		// getOrderList()
	})
	onShow(()=>{
		getOrderList()
	})
</script>

<style lang="less" scoped>
	.pages {
		width: 100%;
		min-height: 100vh;
		background: #F6F6F6;

		.topssechar {
			width: 100%;
			height: 120rpx;
			display: flex;
			align-items: center;
			background: #FFFFFF;
			justify-content: center;

			.searchs {
				background: #FFFFFF;
				border: 1rpx solid rgba(204, 204, 204, 1);
				border-radius: 16rpx;
				width: 690rpx;
				height: 80rpx;
				display: flex;
				align-items: center;

				.search_icon {
					width: 48rpx;
					height: 48rpx;
					margin-left: 30rpx;
					margin-right: 10rpx;
				}
			}

		}

		.tabBar {
			width: 100%;
			height: 88rpx;
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.itemsTOp {
				width: 33%;
				height: 100%;
				font-family: PingFangSC-Regular;
				font-size: 28rpx;
				color: #4E4E4E;
				text-align: center;
				line-height: 28rpx;
				font-weight: 400;
				// border: 1px solid;
				display: flex;
				align-items: center;
				justify-content: center;
				position: relative;

				.lins {
					background: #EE7930;
					border-radius: 5rpx;
					width: 36rpx;
					height: 4rpx;
					position: absolute;
					bottom: 0;
				}
			}

			.selectClass {
				font-family: PingFangSC-Semibold;
				font-size: 32rpx;
				color: #333333;
				text-align: center;
				line-height: 28rpx;
				font-weight: 600;
			}
		}

		.konList {
			width: 100%;
			height: 800rpx;
			display: flex;
			flex-direction: column;
			// justify-content: center;
			align-items: center;
			margin-top: 100rpx;

			.kongs {
				width: 179rpx;
				height: 145rpx;
			}

			.titils {
				font-family: PingFangSC-Regular;
				font-size: 26rpx;
				color: #999999;
				text-align: center;
				font-weight: 400;
			}

		}
	}
</style>